package com.sxs.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sxs.model.Per_user;
import com.sxs.model.Per_user_education;
import com.sxs.model.Per_user_note;
import com.sxs.model.Per_user_vacancies;
import com.sxs.service.PersonalAddServiceInterface;

@Controller
@RequestMapping(value = "/user")
public class PersonnelFilesController {
	private static Logger logger = Logger.getLogger(PersonnelFilesController.class);

	private PersonalAddServiceInterface paService;

	@Autowired
	public void setPaService(PersonalAddServiceInterface paService) {
		this.paService = paService;
	}

	/**
	 * 跳转用户档案添加页面
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/addEmployee", method = RequestMethod.GET)
	public ModelAndView addEmployee(HttpServletRequest request) {
		String deptId = request.getParameter("deptId");
		String deptName = request.getParameter("deptName");
		ModelAndView mv = new ModelAndView("/employee/AddEmployee");
		mv.addObject("deptId",deptId);
		mv.addObject("deptName",deptName);
		return mv;
	}

	/**
	 * 用户档案新增方法
	 * 
	 * @param request
	 * @param perUser
	 * @param perUserVacancies
	 * @param perUserEducation
	 * @param perUserNote
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/addUser", method = RequestMethod.GET)
	public ModelAndView getAddUser(HttpServletRequest request, Per_user perUser, Per_user_vacancies perUserVacancies,
			Per_user_education perUserEducation, Per_user_note perUserNote, HttpSession session) {
		try {
			ModelAndView mv = paService.getAddPersonal(perUser, perUserVacancies, perUserEducation, perUserNote);
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("\n -------------error信息开始-------------- \n" + e
					+ "\n -----------------error信息结束------------------\n\n");
			return null;
		}
	}

	/**
	 * 用户档案查询方法
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/selectUser", method = RequestMethod.GET)
	public ModelAndView getSelectUser(HttpServletRequest request) {
		ModelAndView mv = paService.getSelectPersonal(request);
		return mv;
	}

	/**
	 * 用户档案修改方法
	 * 
	 * @param request
	 * @param perUser
	 * @param perUserVacancies
	 * @param perUserEducation
	 * @param perUserNote
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/updateUser", method = RequestMethod.GET)
	public ModelAndView getUpdateUser(HttpServletRequest request, Per_user perUser, Per_user_vacancies perUserVacancies,
			Per_user_education perUserEducation, Per_user_note perUserNote, HttpSession session) {
		ModelAndView mv = paService.getUpdatePersonal(perUser, perUserVacancies, perUserEducation, perUserNote);
		return mv;
	}

	/**
	 * 用户列表查询
	 * 
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/selectListUser", method = RequestMethod.GET)
	public ModelAndView getSelectListUser(HttpServletRequest request, HttpSession session) {
		ModelAndView mv = paService.getSelectListUser(request, session);
		return mv;
	};
	
	/**
	 * 删除用户信息
	 * @param request
	 * @param session
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/deleteUser", method = RequestMethod.GET)
	public void getDeleteUser(HttpServletRequest request, HttpSession session){
		paService.getdeleteUser(request, session);
	}
}
